using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Security.Permissions;
using System.Security.Policy;
using System.Security.Principal;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Colorprj
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// 
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool SetForegroundWindow(IntPtr hWnd);

        [STAThread]
        static void Main()
        {
            //bool createdNew = true;
            //using (Mutex mutex = new Mutex(true, "Colorprj", out createdNew))
            //{
            //    if (createdNew)
            //    {

            AppDomain.CurrentDomain.SetPrincipalPolicy(
                PrincipalPolicy.WindowsPrincipal);

            // Get the current principal and put it into a principal object.
            WindowsPrincipal myPrincipal = (Thread.CurrentPrincipal
                as WindowsPrincipal);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmLogin());
            //}
            //else
            //{
            //    Process current = Process.GetCurrentProcess();
            //    foreach (Process process in Process.GetProcessesByName(current.ProcessName))
            //    {
            //        if (process.Id != current.Id)
            //        {
            //            SetForegroundWindow(process.MainWindowHandle);
            //            break;
            //        }
            //    }
            //}
        }
        //{

        //  AppDomain.CurrentDomain.SetPrincipalPolicy(
        //PrincipalPolicy.WindowsPrincipal);

        //  // Get the current principal and put it into a principal object.
        //  WindowsPrincipal myPrincipal = (Thread.CurrentPrincipal
        //      as WindowsPrincipal);


        //    Application.EnableVisualStyles();
        //    Application.SetCompatibleTextRenderingDefault(false);
        //    Application.Run(new frmLogin());
        //}
        ////}
    }
}